<template>
  <div>
    <header class="site-header jumbotron">
      <div class="container">
        <div class="row">
          <div class="col-xs-12">
            <h1>请发表对Vue的评论222</h1>
          </div>
        </div>
      </div>
    </header>
    <div class="container">
      <comment-add :addComment="addComment"/>
      <comment-list :comments="comments" :deleteComment="deleteComment"/>
    </div>
  </div>
</template>

<script>
import {nanoid} from 'nanoid'
import CommentAdd from './components/CommentAdd.vue';
import CommentList from './components/CommentList.vue';

export default {
  components: { CommentAdd, CommentList },
  name: 'App',
  data () {
    return {
      comments: []
    }
  },

  methods: {
    addComment (name, content) {
      const comment = {
        id: nanoid(),
        name,
        content
      }
      this.comments.unshift(comment)
    },

    deleteComment (id) {
      this.comments = this.comments.filter(c => c.id!=id)
    }
  }
};
</script>
    
